{# The provided implementation caters for only one reCAPTCHA on a page. Override this template and its logic as needed. #}
<script src="https://{{ recaptcha_domain }}/recaptcha/api.js?render={{ public_key }}{% if api_params %}&{{ api_params }}{% endif %}"></script>
<script>
    var element
    grecaptcha.ready(function() {
        element = document.querySelector('.g-recaptcha[data-widget-uuid="{{ widget_uuid }}"]');
        element.form.addEventListener('submit', recaptchaFormSubmit);
    });
    function recaptchaFormSubmit(event) {
        event.preventDefault();
        {% if action %}
        grecaptcha.execute('{{ public_key }}', {action: '{{ action|escape }}'})
        {% else %}
        grecaptcha.execute('{{ public_key }}', {})
        {% endif %}
        .then(function(token) {
            console.log("reCAPTCHA validated for 'data-widget-uuid=\"{{ widget_uuid }}\"'. Setting input value...")
            element.value = token;
            element.form.submit();
        });
    }
</script>
